001 /*
002 * Copyright 2005 Stephen J. McConnell.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
013 * implied.
014 *
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019 package net.dpml.station;
020
021 import net.dpml.lang.ValuedEnum;
022
023 /**
024 * Lifestyle policy enumeration.
025 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
026 * @version 1.0.1
027 */
028 public final class ProcessState extends ValuedEnum implements Comparable
029 {
030 static final long serialVersionUID = 1L;
031
032 /**
033 * Idle state.
034 */
035 public static final ProcessState IDLE = new ProcessState( "idle", 0 );
036
037 /**
038 * Starting state.
039 */
040 public static final ProcessState STARTING = new ProcessState( "starting", 1 );
041
042 /**
043 * Started state.
044 */
045 public static final ProcessState STARTED = new ProcessState( "started", 2 );
046
047 /**
048 * Started state.
049 */
050 public static final ProcessState STOPPING = new ProcessState( "stopping", 3 );
051
052 /**
053 * Started state.
054 */
055 public static final ProcessState STOPPED = new ProcessState( "stopped", 3 );
056
057 /**
058 * Array of state enumeration values.
059 */
060 private static final ProcessState[] ENUM_VALUES =
061 new ProcessState[]{IDLE, STARTING, STARTED, STOPPING, STOPPED};
062
063 /**
064 * Returns an array of activation enum values.
065 * @return the activation policies array
066 */
067 public static ProcessState[] values()
068 {
069 return ENUM_VALUES;
070 }
071
072 /**
073 * Internal constructor.
074 * @param label the enumeration label.
075 * @param index the enumeration index.
076 */
077 private ProcessState( String label, int index )
078 {
079 super( label, index );
080 }
081
082 /**
083 * Return a string representation of the state.
084 * @return the string value
085 */
086 public String toString()
087 {
088 return getName().toUpperCase();
089 }
090
091 /**
092 * Return a state value matching the supplied value.
093 * @param value the state name
094 * @return the state
095 * @exception IllegalArgumentException if the name if not recognized
096 */
097 public static ProcessState parse( String value ) throws IllegalArgumentException
098 {
099 if( value.equalsIgnoreCase( "idle" ) )
100 {
101 return IDLE;
102 }
103 else if( value.equalsIgnoreCase( "starting" ) )
104 {
105 return STARTING;
106 }
107 else if( value.equalsIgnoreCase( "started" ) )
108 {
109 return STARTED;
110 }
111 else if( value.equalsIgnoreCase( "stopping" ) )
112 {
113 return STOPPING;
114 }
115 else if( value.equalsIgnoreCase( "stopped" ) )
116 {
117 return STOPPED;
118 }
119 else
120 {
121 final String error =
122 "Unrecognized state argument [" + value + "]";
123 throw new IllegalArgumentException( error );
124 }
125 }
126 }
127